import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import {NaiveUiResolver} from "unplugin-vue-components/resolvers";

export default defineConfig({
  base: "./",
  plugins: [
    vue(),
    AutoImport({
      imports: [
        'vue',
        {
          'naive-ui': [
            'useDialog',
            'useMessage',
            'useNotification',
            'useLoadingBar'
          ]
        }
      ]
    }),
    Components({
      resolvers: [NaiveUiResolver()]
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  css:{
    preprocessorOptions:{
      scss: {
        additionalData: '@import "@/assets/styles/scss/constant.scss";'
      }
    }
  },
  //跨域问题解决
  server: {
    cors: true,
    proxy: {
      '/spring': {  //建立访问路径 /store
        //设置访问/store的根路径，后续的路径会在上面相加
        target: 'http://127.0.0.1:8080',
        changeOrigin: true,
        ws: true,
        // 重新将路径改写到store上面
        rewrite: (path) => path.replace(/^\/spring/, '')
      },
      '/flask': {
        target: 'http://127.0.0.1:5000',
        changeOrigin: true,
        ws: true,
        // 重新将路径改写到store上面
        rewrite: (path) => path.replace(/^\/flask/, '')
      }
    },
    preview: {
      port: 5173
    }
  }
})
